package mysql

import "gorm.io/gorm"

// 用户表
type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(30);not null;commit:账号"`
	PassWord string `gorm:"type:char(32);commit:密码"`
}

// 商品表
type Goods struct {
	gorm.Model
	Name  string  `gorm:"type:varchar(20);not null;commit:商品名称"`
	Price float64 `gorm:"type:decimal(10,2);commit:商品价格"`
	Stock int     `gorm:"type:int;commit:商品库存"`
}

func (g *Goods) Find(name string) error {
	return DB.Where("name = ?", name).Find(&g).Error
}

func (g *Goods) Create() error {
	return DB.Create(&g).Error
}

func (g *Goods) Finds(id int) error {
	return DB.Where("id = ?", id).Find(&g).Error
}
func (g *Goods) Update(num int) error {
	return DB.Where("num = ?", num).Updates(&g).Error
}
